package com.bdqn.t362.user.servlet;

import com.bdqn.t362.common.utils.EmailUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author lqm
 * @ClassName ${NAME}
 * @description: TODO
 */
@WebServlet( "/SendEmailServlet")
public class SendEmailServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String email = request.getParameter("email");

        String codeStr = String.valueOf((int) ((Math.random()*9+1)*1000));

        PrintWriter out = response.getWriter();

        if(EmailUtil.sendEmail(email,"登录验证码","您的验证码为："+codeStr)){
            HttpSession session = request.getSession();
            session.setAttribute(email+codeStr,codeStr);
            out.print("0");
        }else{
            out.print("1");
        }



    }
}
